package hu.myai.tick;

import hu.myai.api.tick.AbstractTickProvider;
import hu.myai.model.TickVO;
import hu.myai.util.CommonUtil;
import hu.myai.util.web.DownloadASXStockData;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author bozbalint
 * 
 */
public class YahooWebHistoryTick extends AbstractTickProvider {

	/**
	 * The object used when logging debug,errors,warnings and info.
	 * */
	private final Logger log = LoggerFactory.getLogger(this.getClass());

	private String symbol;

	private Date initDate = CommonUtil.parseDate("2009-01-01");

	public YahooWebHistoryTick() {
		super("YahooWebHistoryTick");
	}

	public static void main(String[] args) {
		YahooWebHistoryTick tickManager = new YahooWebHistoryTick();

		tickManager.symbol = "BHP";

		tickManager.start();
	}

	public void start() {

		DownloadASXStockData webdata = new DownloadASXStockData();

		List<TickVO> tickList = webdata.getYahooHistory(initDate, new Date(), symbol);

		int i = 0;
		for (TickVO tick : tickList) {
			tick.setTimestamp(i++);

			log.debug("in="+tick.toString());
			propegateTick(tick);
		}
	}

	@Override
	public String getSymbol() {
		return this.symbol;
	}

	/**
	 * @param symbol
	 *            the symbol to set
	 */
	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	/**
	 * @param initDate
	 *            the initDate to set
	 */
	public void setInitDate(String initDate) {
		this.initDate = CommonUtil.parseDate(initDate);
	}
}
